package org.example.admin.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.example.admin.service.AdminAdService;
import org.example.common.utils.ResponseUtil;
import org.example.db.entity.Ad;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/ad")
@Api(tags = "对广告的操作")
public class AdminAdController {
    AdminAdService adminAdService;

    public AdminAdController(AdminAdService adminAdService) {
        this.adminAdService = adminAdService;
    }

    @GetMapping("/list")
    public Object getAd(){

        return ResponseUtil.ok(adminAdService.getAdGoodsList());
    }

    @PostMapping("/update")
    public Object updateAd(@RequestBody Ad ad){

        adminAdService.updateAd(ad);
        return ResponseUtil.ok();
    }

    @PostMapping("/delete")
    public Object deleteAd(@RequestBody Ad ad){

        adminAdService.deleteAd(ad);
        return ResponseUtil.ok();
    }

    @PostMapping("/create")
    @ApiOperation("添加广告")
    public Object create(@RequestBody Ad ad){
        adminAdService.add(ad);
        return ResponseUtil.ok();
    }
}
